package cn.sxt.yxl.question.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.sxt.common.util.PageInfoUtil;
import cn.sxt.yxl.question.dao.IAColumnsDao;
import cn.sxt.yxl.question.pojo.AColumns;
import cn.sxt.yxl.question.service.IQuestionService;

@Service("questionService")
public class QuestionServiceImp implements IQuestionService{

	@Resource
	private IAColumnsDao columnsDao;
	/*--------------------- 栏目模块开始---------------- */
	@Override
	public AColumns findOneAdminService(Map<String, Object> condMap) {
		
		return columnsDao.findOne(condMap);
	}

	@Override
	public JSONObject saveOneAdminService(AColumns columns) {
		JSONObject resultJson = new JSONObject();
		int res = columnsDao.saveOne(columns);
		if(res>0){
			JSONObject dataJson = new JSONObject();
			dataJson.put("id", columns.getId());
			dataJson.put("effectCount", res);
			resultJson.put("code", "1");
			resultJson.put("info", "成功");
			resultJson.put("data", dataJson);
		}else{
			resultJson.put("code", "0");
			resultJson.put("info", "失败");
		}
		return resultJson;
	}

	@Override
	public JSONObject updateOneAdminService(AColumns columns) {
		JSONObject resultJson = new JSONObject();
		int res = columnsDao.updateOne(columns);
		if(res>0){
			JSONObject dataJson = new JSONObject();
			dataJson.put("id", columns.getId());
			dataJson.put("effectCount", res);
			resultJson.put("code", "1");
			resultJson.put("info", "成功");
			resultJson.put("data", dataJson);
		}else{
			resultJson.put("code", "0");
			resultJson.put("info", "失败");
		}
		return resultJson;
	}

	@Override
	public JSONObject deleteOneAdminService(AColumns columns) {
		JSONObject resultJson = new JSONObject();
		int res = columnsDao.deleteOne(columns);
		if(res>0){
			JSONObject dataJson = new JSONObject();
			dataJson.put("id", columns.getId());
			dataJson.put("effectCount", res);
			resultJson.put("code", "1");
			resultJson.put("info", "成功");
			resultJson.put("data", dataJson);
		}else{
			resultJson.put("code", "0");
			resultJson.put("info", "失败");
		}
		return resultJson;
	}

	@Override
	public List<AColumns> findCondAdminListService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap) {
		if(pageInfoUtil != null){
			/* 查询总记录数 */
			Page page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			/* 查询数据 */
			List<AColumns> columnsList = columnsDao.findCondList(condMap);
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal()+""));
			return columnsList;
		}
		return columnsDao.findCondList(condMap);
	}
	/*--------------------- 栏目模块开始---------------- */
}
